<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
    <meta name="author" content="">
    <title></title>  <link rel="icon" href="/template/pc1/images/wmh_favicon.ico" type="image/x-icon" />
    <% include("../inc/input_css.html"){}%>

</head>
<body>
<div class="ibox">
    <div class="ibox-title">
        <div class="pull-left mbx navbar_title">
            <span class="current">赠品管理</span>
            <span class="line">/</span>
            添加礼品
        </div>
    </div>
    <div class="ibox-content">
        <div class="wrapper wrapper-content">
            <div class="row">
                <div class="padding-40">
                    <form id="inputForm" action="savegift" method="post">
                        <input type="hidden" name="productId" value="${productId!}"/>
                        <table class="input" id="productGiftTable">
                            <div class="form-group">
                                <label class="col-sm-1 control-label">类型：</label>
                                <div class="col-sm-3">
                                    <select id="type" name="specification.type" value="${specification.type!}" class="form-control light-input" style="height: 32px">
                                        <option value="text">文本</option>
                                        <option value="image">图片</option>
                                    </select>
                                </div>
                                <div href="javascript:;" id="ddProductGiftButton" class="button hive-btn hive-btn-primary margin-left-15">
                                    <i class="icon-add" aria-hidden="true"></i>增加礼品
                                </div>
                            </div>
                            <tr>
                                <!--<td>
                                    &nbsp;
                                </td>-->
                               <!-- <td colspan="4">
                                    <div href="javascript:;" id="ddProductGiftButton" class="button hive-btn hive-btn-primary margin-left-15">
                                        <i class="icon-add" aria-hidden="true"></i>增加礼品
                                    </div>
                                </td>-->
                            </tr>
                            <tr class="title">
                                <td>
                                    &nbsp;
                                </td>
                                <td>
                                    礼品名称
                                </td>
                                <td>
                                    礼品描述
                                </td>
                                <td>
                                    数量
                                </td>
                                <td>
                                    删除
                                </td>
                            </tr>

                            <%if(productGifts.~size>0){%>
                                <%for(list in productGifts){%>
                                    <%if(list.imgurl!=null){%>
                                        <tr class="productGiftTr">
                                            <td>
                                                &nbsp;
                                            </td>
                                            <td>
                                                <input type="text" name="productGift[${listLP.index-1}].name" class="text productGiftName" maxlength="200" value="${list.name}"/>
                                            </td>
                                            <td>
                                                <span class="fieldSet">
                                                    <input type="text" name="productGift[${listLP.index-1}].describe" class="text productGiftDescribe" maxlength="200" value="${list.describe}"/>
                                                    <input type="hidden" name="productGift[${listLP.index-1}].imgurl" value="${list.imgurl!}" class="pull-left form-control light-input"/>
                                                    <img class="img-rounded" src="${list.imgurl!}" style="max-height:50px;"/>
                                                  <input type="button" class="button browserButton" value="选择文件" />
                                                </span>
                                            </td>
                                            <td>
                                                <input type="text" name="productGift[${listLP.index-1}].num" class="text productGiftNum" maxlength="9" value="${list.num}" style="width: 30px;text-align: center" />
                                            </td>
                                            <td>
                                                <a href="javascript:void(0)" class="icon-delete hive_icon color_danger deleteProductGift" data-toggle="tooltip" data-placement="top" title="删除"></a>
                                            </td>
                                            <input type="hidden" name="productGift[${listLP.index-1}].id" value="${list.id}"/>
                                        </tr>
                                    <%}else{%>
                                        <tr class="productGiftTr">
                                            <td>
                                                &nbsp;
                                            </td>
                                            <td>
                                                <input type="text" name="productGift[${listLP.index-1}].name" class="text productGiftName" maxlength="200" value="${list.name}"/>
                                            </td>
                                            <td>
                                                <span class="fieldSet">
                                                    <input type="text" name="productGift[${listLP.index-1}].describe" class="text productGiftDescribe" maxlength="200" value="${list.describe}"placeholder="请填写相关描述"/>
                                                    <!--   <input type="hidden" name="productGift[${listLP.index-1}].imgurl" value="${list.imgurl!}" class="pull-left form-control light-input"/>
                                                           <img class="img-rounded" src="${list.imgurl!}" style="max-height:50px;"/>
                                                   <input type="button" class="button browserButton" value="选择文件" />-->
                                                </span>
                                            </td>
                                            <td>
                                                <input type="text" name="productGift[${listLP.index-1}].num" class="text productGiftNum" maxlength="9" value="${list.num}" style="width: 30px;text-align: center" />
                                            </td>
                                            <td>
                                                <a href="javascript:void(0)" class="icon-delete hive_icon color_danger deleteProductGift" data-toggle="tooltip" data-placement="top" title="删除"></a>
                                            </td>
                                            <input type="hidden" name="productGift[${listLP.index-1}].id" value="${list.id}"/>
                                        </tr>
                                    <%}%>
                                <%}%>
                            <%}else{%>
                                <tr class="productGiftTr">
                                    <td>
                                        &nbsp;
                                    </td>
                                    <td>
                                        <input type="text" name="productGift[0].name" class="text productGiftName" maxlength="200" />
                                    </td>
                                    <td>
                                    <span class="fieldSet">
                                        <input type="text" name="productGift[0].describe" class="text productGiftDescribe" maxlength="200" placeholder="请填写相关描述"/>
                                   <!-- <input type="button" class="button browserButton" value="选择文件" />-->
                                    </span>
                                    </td>
                                    <td>
                                        <input type="text" name="productGift[0].num" class="text productGiftNum" maxlength="9" style="width: 30px;text-align: center" />
                                    </td>
                                    <td>
                                        <a href="javascript:void(0)" class="icon-delete hive_icon color_danger deleteProductGift" data-toggle="tooltip" data-placement="top" title="删除"></a>
                                    </td>
                                </tr>
                            <%}%>


                        </table>
                        <div class="form-group" style="margin-top: 50px;text-align: center">
                            <label class="col-sm-2 control-label "></label>
                            <div class="col-sm-6 col-sm-offset-0">
                                <button class="hive-btn-cancle" id="btn_cancle" type="button" onclick="history.back()">&nbsp;取消&nbsp;</button>
                                <button class="hive-btn hive-btn-primary margin-left-30" type="submit">&nbsp;提交&nbsp;
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>




<% include("../inc/input_js.html"){}%>

<!-- 自定义js -->
<script src="/res/js/jquery-migrate-1.2.1.js"></script><!--jquery1.9 以上补丁-->
<script type="text/javascript">
    var uploadUrl="/file/uploadfile?shopId=${shopId!}&type=d";
    var browserUrl="/file/browser?shopId=${shopId!}";
</script>
<script src="https://static.9hive.cn/global/vendor/file/file.js"></script>
<script type="text/javascript">
    $(function () {
        $("input.browserButton").browser();
        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_flat-blue',
            radioClass: 'iradio_flat-blue',
        });

    })


</script>
<script type="text/javascript">
    //礼品赠送
    $().ready(function() {
        var $inputForm = $("#inputForm");
        var $productGiftTable = $("#productGiftTable");
        var $type = $("#type");
        var $ddProductGiftButton = $("#ddProductGiftButton");
        var $deleteProductGift = $("a.deleteProductGift");
        var productGiftIndex;
        if(${productGifts.~size}>0){
            productGiftIndex =${productGifts.~size};
        }else{
            productGiftIndex=1;
        }

        // 修改规格类型
        $type.change(function() {
            if ($(this).val() == "text") {
                $("input.productGiftImage").val("").prop("disabled", true);
                $("input.browserButton").prop("disabled", true);
            } else {
                $("input.productGiftImage").prop("disabled", false);
                $("input.browserButton").prop("disabled", false);
            }
        });

        //$("input.browserButton").browser();


        $("#ddProductGiftButton").on(function () {

        });
        // 增加规格值
        $ddProductGiftButton.click(function() {

            if ($type.val() == "text") {
                var trHtml = '<tr class="productGiftTr"> <td> &nbsp; <\/td> <td> <input type="text" name="productGift[' + productGiftIndex + '].name" maxlength="200" class="text productGiftName" \/> <\/td> <td> <span class="fieldSet"> <input type="text" name="productGift[' + productGiftIndex + '].describe" maxlength="200" class="text productGiftDescribe" placeholder="请填写相关描述"  \/>  <\/span> <\/td> <td> <input type="text" name="productGift[' + productGiftIndex + '].num" maxlength="9" class="text productGiftNum" style="width: 30px;text-align:center" \/> <\/td> <td> <a href="javascript:void(0)" class="icon-delete hive_icon color_danger deleteProductGift" data-toggle="tooltip" data-placement="top" title="删除"></a> <\/td> <\/tr>';
            } else {
                var trHtml = '<tr class="productGiftTr"> <td> &nbsp; <\/td> <td> <input type="text" name="productGift[' + productGiftIndex + '].name" class="text productGiftName" maxlength="200" \/> <\/td> <td> <span class="fieldSet"> <input type="text" name="productGift[' + productGiftIndex + '].describe" maxlength="200" class="text productGiftDescribe"  \/> <input type="hidden" name="productGift[' + productGiftIndex + '].imgurl"  class="pull-left form-control light-input"/><img class="img-rounded"  style="max-height:50px;"/><input type="button" class="button browserButton margin-left-4" value="选择文件" /><\/span> <\/td> <td> <input type="text" name="productGift[' + productGiftIndex + '].num" class="text productGiftNum" maxlength="9" style="width: 30px;text-align:center" \/> <\/td> <td><a href="javascript:void(0)" class="icon-delete hive_icon color_danger deleteProductGift" data-toggle="tooltip" data-placement="top" title="删除"></a> <\/td> <\/tr>';		}
            $productGiftTable.append(trHtml).find("input.browserButton:last").browser();
            productGiftIndex ++;
        });

        // 删除规格值
        $deleteProductGift.live("click", function() {
            var $this = $(this);
            var $productId=$(this).parent().next().val();
            if(!$productId){
                $this.closest("tr").remove();
               /* toastr.success('删除成功', '提示')*/
                parent.layer.msg("删除成功!");

            }else{
                $.ajax({
                   url: "deletegift",
                    type:"GET",
                    data:{
                        "id":$productId
                    },
                    success:function(data){
                        if(data.status=='success'){
                            $this.closest("tr").remove();
                          /*toastr.success('删除成功', '提示')*/
                            parent.layer.msg("删除成功!");
                        }
                    }
                })
            }
        });

        $.validator.addClassRules({
            productGiftName: {
                required: true
            },
            /*productGiftImage: {
             required: true
             },*/
            productGiftNum: {
                required: true,
                digits: true
            }
        });

        // 表单验证
        $inputForm.validate({
            rules: {
                name: "required",
                order: "digits"
            }
        });

    });
</script>
</body>
</html>